// 封装倒计时逻辑函数
import {ref,computed,onMounted} from 'vue'


export const useCountDown = () =>{
  //1.响应式的数据
  const time = ref(0)

  const formatTime = computed(()=>{
    dayjs.unix(time.value).formart("mm分ss秒")
  })

  //2.开启倒计时函数
  const start = (currentTime) => {
    //开始倒计时的逻辑
    //每隔1s
    formatTime.value = currentTime
    setInterval(()=>{
      time.value--
    },1000)
  }

onMounted(()=>{
  time && clearInterval(time)
})

  return {
    formatTime,
    start
  }
}
